<template>
  <view class="address-container">
    <!-- 顶部导航栏 -->
    <view class="header">
      <view class="header-content">
        <view class="back-btn" @tap="goBack">
          <text class="back-icon">←</text>
        </view>
        <view class="header-title">添加新地址</view>
        <view class="header-placeholder"></view>
      </view>
    </view>

    <!-- 表单内容 -->
    <view class="form-content">
      <!-- 收货人信息卡片 -->
      <view class="form-card">
        <view class="card-title">
          <text class="title-icon">👤</text>
          <text class="title-text">收货人信息</text>
        </view>
        
        <!-- 姓名输入 -->
        <view class="form-item">
          <view class="form-label">收货人姓名</view>
          <input 
            v-model="formData.client" 
            placeholder="请输入收货人姓名" 
            class="form-input"
            maxlength="20"
          />
        </view>

        <!-- 电话输入 -->
        <view class="form-item">
          <view class="form-label">联系电话</view>
          <input 
            v-model="formData.clientPhone" 
            placeholder="请输入联系电话" 
            class="form-input"
            type="number"
            maxlength="11"
          />
        </view>

        <!-- 性别选择 -->
        <view class="form-item">
          <view class="form-label">性别</view>
          <view class="gender-selector">
            <view 
              class="gender-option" 
              :class="{ active: sexIndex === 0 }"
              @tap="selectGender(0)"
            >
              <text class="gender-icon">👨</text>
              <text class="gender-text">男</text>
            </view>
            <view 
              class="gender-option" 
              :class="{ active: sexIndex === 1 }"
              @tap="selectGender(1)"
            >
              <text class="gender-icon">👩</text>
              <text class="gender-text">女</text>
            </view>
          </view>
        </view>
      </view>

      <!-- 地址信息卡片 -->
      <view class="form-card">
        <view class="card-title">
          <text class="title-icon">📍</text>
          <text class="title-text">地址信息</text>
        </view>
        
        <!-- 省市区选择 -->
        <view class="form-item">
          <view class="form-label">所在地区</view>
          <view class="region-picker">
            <picker @change="provinceChange" :value="provinceIndex" :range="provinces" range-key="name">
              <view class="picker-item" :class="{ placeholder: !provinces[provinceIndex] }">
                <text>{{ provinces[provinceIndex]?.name || '请选择省份' }}</text>
                <text class="picker-arrow">▼</text>
              </view>
            </picker>
            <picker @change="cityChange" :value="cityIndex" :range="cities" range-key="name" :disabled="!provinces[provinceIndex]">
              <view class="picker-item" :class="{ placeholder: !cities[cityIndex], disabled: !provinces[provinceIndex] }">
                <text>{{ cities[cityIndex]?.name || '请选择城市' }}</text>
                <text class="picker-arrow">▼</text>
              </view>
            </picker>
            <picker @change="districtChange" :value="districtIndex" :range="districts" range-key="name" :disabled="!cities[cityIndex]">
              <view class="picker-item" :class="{ placeholder: !districts[districtIndex], disabled: !cities[cityIndex] }">
                <text>{{ districts[districtIndex]?.name || '请选择区县' }}</text>
                <text class="picker-arrow">▼</text>
              </view>
            </picker>
          </view>
        </view>

        <!-- 详细地址输入 -->
        <view class="form-item">
          <view class="form-label">详细地址</view>
          <textarea 
            v-model="formData.detailedAddress" 
            placeholder="请输入详细地址，如街道、门牌号等" 
            class="form-textarea"
            :maxlength="100"
          />
          <view class="char-count" :class="{ warning: formData.detailedAddress.length > 80 }">
            {{ formData.detailedAddress.length }}/100
          </view>
        </view>
      </view>

      <!-- 完整地址预览 -->
      <view class="form-card" v-if="fullAddress">
        <view class="card-title">
          <text class="title-icon">📋</text>
          <text class="title-text">地址预览</text>
        </view>
        <view class="address-preview">
          <text class="preview-text">{{ fullAddress }}</text>
        </view>
      </view>
    </view>

    <!-- 提交按钮 -->
    <view class="submit-section">
      <button class="submit-btn" @tap="submitAddress" :disabled="!isFormValid" :class="{ disabled: !isFormValid }">
        <text class="btn-text">保存地址</text>
        <text class="btn-icon">✓</text>
      </button>
    </view>

    <!-- 加载状态 -->
    <view v-if="loading" class="loading-overlay">
      <view class="loading-content">
        <view class="loading-spinner"></view>
        <text class="loading-text">正在保存地址...</text>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue';
import { get, post } from '@/utils/request.js';

// 高德地图API密钥 - 请替换为你的实际密钥
const AMAP_KEY = 'your_amap_key_here';

// 页面模式：add(新增) 或 edit(编辑)
const pageMode = ref('add');
const currentAddressId = ref(null);

// 表单数据
const formData = ref({
  client: '',
  clientPhone: '',
  clientSex: 1,
  detailedAddress: ''
});

// 性别选择
const sexList = ['男', '女'];
const sexIndex = ref(0);

// 省市区数据
const provinces = ref([]);
const cities = ref([]);
const districts = ref([]);
const provinceIndex = ref(0);
const cityIndex = ref(0);
const districtIndex = ref(0);

// 状态
const loading = ref(false);

// 计算完整地址
const fullAddress = computed(() => {
  const province = provinces.value[provinceIndex.value]?.name || '';
  const city = cities.value[cityIndex.value]?.name || '';
  const district = districts.value[districtIndex.value]?.name || '';
  const detailed = formData.value.detailedAddress || '';
  
  if (!province || !city || !district) return '';
  
  return `${province}${city}${district}${detailed}`;
});

// 表单验证
const isFormValid = computed(() => {
  return formData.value.client.trim() && 
         formData.value.clientPhone.trim() && 
         fullAddress.value.trim();
});

// 返回上一页
const goBack = () => {
  uni.navigateBack();
};

// 性别选择
const selectGender = (index) => {
  sexIndex.value = index;
  formData.value.clientSex = index;
};

// 省份选择变化
const provinceChange = async (e) => {
  provinceIndex.value = e.detail.value;
  cityIndex.value = 0;
  districtIndex.value = 0;
  
  // 清空城市和区县数据
  cities.value = [];
  districts.value = [];
  
  // 获取城市数据
  await fetchCities(provinces.value[provinceIndex.value].adcode);
};

// 城市选择变化
const cityChange = async (e) => {
  cityIndex.value = e.detail.value;
  districtIndex.value = 0;
  
  // 清空区县数据
  districts.value = [];
  
  // 获取区县数据
  await fetchDistricts(cities.value[cityIndex.value].adcode);
};

// 区县选择变化
const districtChange = (e) => {
  districtIndex.value = e.detail.value;
};

// 获取省份列表
const fetchProvinces = async () => {
  try {
    console.log('开始获取省份列表...');
    
    // 使用uni.request替代直接调用
    const response = await new Promise((resolve, reject) => {
      uni.request({
        url: `https://restapi.amap.com/v3/config/district`,
        method: 'GET',
        data: {
          key: AMAP_KEY,
          keywords: '中国',
          subdistrict: 1,
          extensions: 'base'
        },
        success: (res) => {
          console.log('省份API响应:', res);
          resolve(res);
        },
        fail: (err) => {
          console.error('省份API请求失败:', err);
          reject(err);
        }
      });
    });
    
    if (response.statusCode === 200 && response.data.status === '1') {
      provinces.value = response.data.districts[0].districts || [];
      console.log('省份列表加载成功:', provinces.value);
    } else {
      console.error('省份API返回错误:', response.data);
      // 如果API失败，使用备用数据
      loadBackupProvinces();
    }
  } catch (error) {
    console.error('获取省份列表失败:', error);
    // 使用备用数据
    loadBackupProvinces();
  }
};

// 获取城市列表
const fetchCities = async (adcode) => {
  try {
    console.log('开始获取城市列表，adcode:', adcode);
    
    const response = await new Promise((resolve, reject) => {
      uni.request({
        url: `https://restapi.amap.com/v3/config/district`,
        method: 'GET',
        data: {
          key: AMAP_KEY,
          keywords: adcode,
          subdistrict: 1,
          extensions: 'base'
        },
        success: (res) => {
          console.log('城市API响应:', res);
          resolve(res);
        },
        fail: (err) => {
          console.error('城市API请求失败:', err);
          reject(err);
        }
      });
    });
    
    if (response.statusCode === 200 && response.data.status === '1') {
      cities.value = response.data.districts[0].districts || [];
      console.log('城市列表加载成功:', cities.value);
    } else {
      console.error('城市API返回错误:', response.data);
      // 使用备用城市数据
      loadBackupCities(adcode);
    }
  } catch (error) {
    console.error('获取城市列表失败:', error);
    // 使用备用城市数据
    loadBackupCities(adcode);
  }
};

// 获取区县列表
const fetchDistricts = async (adcode) => {
  try {
    console.log('开始获取区县列表，adcode:', adcode);
    
    const response = await new Promise((resolve, reject) => {
      uni.request({
        url: `https://restapi.amap.com/v3/config/district`,
        method: 'GET',
        data: {
          key: AMAP_KEY,
          keywords: adcode,
          subdistrict: 1,
          extensions: 'base'
        },
        success: (res) => {
          console.log('区县API响应:', res);
          resolve(res);
        },
        fail: (err) => {
          console.error('区县API请求失败:', err);
          reject(err);
        }
      });
    });
    
    if (response.statusCode === 200 && response.data.status === '1') {
      districts.value = response.data.districts[0].districts || [];
      console.log('区县列表加载成功:', districts.value);
    } else {
      console.error('区县API返回错误:', response.data);
      // 使用备用区县数据
      loadBackupDistricts(adcode);
    }
  } catch (error) {
    console.error('获取区县列表失败:', error);
    // 使用备用区县数据
    loadBackupDistricts(adcode);
  }
};

// 备用省份数据（如果API失败时使用）
const loadBackupProvinces = () => {
  console.log('使用备用省份数据');
  provinces.value = [
    { name: '北京市', adcode: '110000' },
    { name: '天津市', adcode: '120000' },
    { name: '河北省', adcode: '130000' },
    { name: '山西省', adcode: '140000' },
    { name: '内蒙古自治区', adcode: '150000' },
    { name: '辽宁省', adcode: '210000' },
    { name: '吉林省', adcode: '220000' },
    { name: '黑龙江省', adcode: '230000' },
    { name: '上海市', adcode: '310000' },
    { name: '江苏省', adcode: '320000' },
    { name: '浙江省', adcode: '330000' },
    { name: '安徽省', adcode: '340000' },
    { name: '福建省', adcode: '350000' },
    { name: '江西省', adcode: '360000' },
    { name: '山东省', adcode: '370000' },
    { name: '河南省', adcode: '410000' },
    { name: '湖北省', adcode: '420000' },
    { name: '湖南省', adcode: '430000' },
    { name: '广东省', adcode: '440000' },
    { name: '广西壮族自治区', adcode: '450000' },
    { name: '海南省', adcode: '460000' },
    { name: '重庆市', adcode: '500000' },
    { name: '四川省', adcode: '510000' },
    { name: '贵州省', adcode: '520000' },
    { name: '云南省', adcode: '530000' },
    { name: '西藏自治区', adcode: '540000' },
    { name: '陕西省', adcode: '610000' },
    { name: '甘肃省', adcode: '620000' },
    { name: '青海省', adcode: '630000' },
    { name: '宁夏回族自治区', adcode: '640000' },
    { name: '新疆维吾尔自治区', adcode: '650000' }
  ];
  
  uni.showToast({
    title: '使用本地省份数据',
    icon: 'none',
    duration: 2000
  });
};

// 备用城市数据
const loadBackupCities = (provinceAdcode) => {
  console.log('使用备用城市数据，省份代码:', provinceAdcode);
  
  // 这里可以根据省份代码返回对应的城市列表
  // 为了简化，我们提供一些主要城市的示例
  const cityMap = {
    '110000': [{ name: '北京市', adcode: '110100' }],
    '120000': [{ name: '天津市', adcode: '120100' }],
    '130000': [
      { name: '石家庄市', adcode: '130100' },
      { name: '唐山市', adcode: '130200' },
      { name: '秦皇岛市', adcode: '130300' },
      { name: '邯郸市', adcode: '130400' },
      { name: '邢台市', adcode: '130500' },
      { name: '保定市', adcode: '130600' },
      { name: '张家口市', adcode: '130700' },
      { name: '承德市', adcode: '130800' },
      { name: '沧州市', adcode: '130900' },
      { name: '廊坊市', adcode: '131000' },
      { name: '衡水市', adcode: '131100' }
    ],
    '310000': [{ name: '上海市', adcode: '310100' }],
    '320000': [
      { name: '南京市', adcode: '320100' },
      { name: '无锡市', adcode: '320200' },
      { name: '徐州市', adcode: '320300' },
      { name: '常州市', adcode: '320400' },
      { name: '苏州市', adcode: '320500' },
      { name: '南通市', adcode: '320600' },
      { name: '连云港市', adcode: '320700' },
      { name: '淮安市', adcode: '320800' },
      { name: '盐城市', adcode: '320900' },
      { name: '扬州市', adcode: '321000' },
      { name: '镇江市', adcode: '321100' },
      { name: '泰州市', adcode: '321200' },
      { name: '宿迁市', adcode: '321300' }
    ],
    '330000': [
      { name: '杭州市', adcode: '330100' },
      { name: '宁波市', adcode: '330200' },
      { name: '温州市', adcode: '330300' },
      { name: '嘉兴市', adcode: '330400' },
      { name: '湖州市', adcode: '330500' },
      { name: '绍兴市', adcode: '330600' },
      { name: '金华市', adcode: '330700' },
      { name: '衢州市', adcode: '330800' },
      { name: '舟山市', adcode: '330900' },
      { name: '台州市', adcode: '331000' },
      { name: '丽水市', adcode: '331100' }
    ],
    '350000': [
      { name: '福州市', adcode: '350100' },
      { name: '厦门市', adcode: '350200' },
      { name: '莆田市', adcode: '350300' },
      { name: '三明市', adcode: '350400' },
      { name: '泉州市', adcode: '350500' },
      { name: '漳州市', adcode: '350600' },
      { name: '南平市', adcode: '350700' },
      { name: '龙岩市', adcode: '350800' },
      { name: '宁德市', adcode: '350900' }
    ],
    '440000': [
      { name: '广州市', adcode: '440100' },
      { name: '韶关市', adcode: '440200' },
      { name: '深圳市', adcode: '440300' },
      { name: '珠海市', adcode: '440400' },
      { name: '汕头市', adcode: '440500' },
      { name: '佛山市', adcode: '440600' },
      { name: '江门市', adcode: '440700' },
      { name: '湛江市', adcode: '440800' },
      { name: '茂名市', adcode: '440900' },
      { name: '肇庆市', adcode: '441200' },
      { name: '惠州市', adcode: '441300' },
      { name: '梅州市', adcode: '441400' },
      { name: '汕尾市', adcode: '441500' },
      { name: '河源市', adcode: '441600' },
      { name: '阳江市', adcode: '441700' },
      { name: '清远市', adcode: '441800' },
      { name: '东莞市', adcode: '441900' },
      { name: '中山市', adcode: '442000' },
      { name: '潮州市', adcode: '445100' },
      { name: '揭阳市', adcode: '445200' },
      { name: '云浮市', adcode: '445300' }
    ]
  };
  
  cities.value = cityMap[provinceAdcode] || [];
  
  if (cities.value.length === 0) {
    uni.showToast({
      title: '该省份暂无城市数据',
      icon: 'none'
    });
  }
};

// 备用区县数据
const loadBackupDistricts = (cityAdcode) => {
  console.log('使用备用区县数据，城市代码:', cityAdcode);
  
  // 这里可以根据城市代码返回对应的区县列表
  // 为了简化，我们提供一些主要区县的示例
  const districtMap = {
    '110100': [
      { name: '东城区', adcode: '110101' },
      { name: '西城区', adcode: '110102' },
      { name: '朝阳区', adcode: '110105' },
      { name: '丰台区', adcode: '110106' },
      { name: '石景山区', adcode: '110107' },
      { name: '海淀区', adcode: '110108' },
      { name: '门头沟区', adcode: '110109' },
      { name: '房山区', adcode: '110111' },
      { name: '通州区', adcode: '110112' },
      { name: '顺义区', adcode: '110113' },
      { name: '昌平区', adcode: '110114' },
      { name: '大兴区', adcode: '110115' },
      { name: '怀柔区', adcode: '110116' },
      { name: '平谷区', adcode: '110117' },
      { name: '密云区', adcode: '110118' },
      { name: '延庆区', adcode: '110119' }
    ],
    '310100': [
      { name: '黄浦区', adcode: '310101' },
      { name: '徐汇区', adcode: '310104' },
      { name: '长宁区', adcode: '310105' },
      { name: '静安区', adcode: '310106' },
      { name: '普陀区', adcode: '310107' },
      { name: '虹口区', adcode: '310109' },
      { name: '杨浦区', adcode: '310110' },
      { name: '闵行区', adcode: '310112' },
      { name: '宝山区', adcode: '310113' },
      { name: '嘉定区', adcode: '310114' },
      { name: '浦东新区', adcode: '310115' },
      { name: '金山区', adcode: '310116' },
      { name: '松江区', adcode: '310117' },
      { name: '青浦区', adcode: '310118' },
      { name: '奉贤区', adcode: '310120' },
      { name: '崇明区', adcode: '310151' }
    ],
    '350200': [
      { name: '思明区', adcode: '350203' },
      { name: '海沧区', adcode: '350205' },
      { name: '湖里区', adcode: '350206' },
      { name: '集美区', adcode: '350211' },
      { name: '同安区', adcode: '350212' },
      { name: '翔安区', adcode: '350213' }
    ],
    '440300': [
      { name: '罗湖区', adcode: '440303' },
      { name: '福田区', adcode: '440304' },
      { name: '南山区', adcode: '440305' },
      { name: '宝安区', adcode: '440306' },
      { name: '龙岗区', adcode: '440307' },
      { name: '盐田区', adcode: '440308' },
      { name: '龙华区', adcode: '440309' },
      { name: '坪山区', adcode: '440310' },
      { name: '光明区', adcode: '440311' }
    ]
  };
  
  districts.value = districtMap[cityAdcode] || [];
  
  if (districts.value.length === 0) {
    uni.showToast({
      title: '该城市暂无区县数据',
      icon: 'none'
    });
  }
};

// 解析地址字符串，提取省市区信息
const parseAddress = (addressStr) => {
  if (!addressStr) return { province: '', city: '', district: '', detailed: '' };
  
  // 简单的地址解析逻辑，可以根据实际需求优化
  const address = addressStr.trim();
  
  // 这里可以根据实际地址格式进行解析
  // 暂时返回空值，让用户重新选择
  return {
    province: '',
    city: '',
    district: '',
    detailed: address
  };
};

// 初始化编辑数据
const initEditData = () => {
  const pages = getCurrentPages();
  const currentPage = pages[pages.length - 1];
  const options = currentPage.options;
  
  if (options.mode === 'edit') {
    pageMode.value = 'edit';
    currentAddressId.value = parseInt(options.addressId);
    
    // 设置表单数据
    formData.value = {
      client: decodeURIComponent(options.client || ''),
      clientPhone: decodeURIComponent(options.clientPhone || ''),
      clientSex: parseInt(options.clientSex) || 1,
      detailedAddress: decodeURIComponent(options.address || '')
    };
    
    // 设置性别选择
    sexIndex.value = formData.value.clientSex;
    
    console.log('编辑模式初始化:', formData.value);
  }
};

// 提交地址
const submitAddress = async () => {
  if (!isFormValid.value) {
    uni.showToast({
      title: '请完善地址信息',
      icon: 'none'
    });
    return;
  }

  loading.value = true;
  
  try {
    // 构建完整的地址字符串
    const completeAddress = fullAddress.value;
    
    if (pageMode.value === 'edit') {
      // 编辑模式：调用修改接口
      const params = {
        addressId: currentAddressId.value,
        address: completeAddress,
        client: formData.value.client.trim(),
        clientPhone: formData.value.clientPhone.trim(),
        clientSex: formData.value.clientSex
      };

      console.log('修改地址参数:', params);
      const response = await get('/adress/useradressup', params);
      
      if (response.data.code === 200) {
        uni.showToast({
          title: '地址修改成功',
          icon: 'success'
        });
        
        setTimeout(() => {
          uni.navigateBack();
        }, 1500);
      } else {
        uni.showToast({
          title: response.data.msg || '地址修改失败',
          icon: 'none'
        });
      }
    } else {
      // 新增模式：调用新增接口
      const params = {
        address: completeAddress,
        userId: 3,
        client: formData.value.client.trim(),
        clientPhone: formData.value.clientPhone.trim(),
        clientSex: formData.value.clientSex
      };

      console.log('新增地址参数:', params);
      const response = await get('/adress/useradressint', params);
      
      if (response.data.code === 200) {
        uni.showToast({
          title: '地址保存成功',
          icon: 'success'
        });
        
        setTimeout(() => {
          uni.navigateBack();
        }, 1500);
      } else {
        uni.showToast({
          title: response.data.msg || '地址保存失败',
          icon: 'none'
        });
      }
    }
  } catch (error) {
    console.error('地址操作失败:', error);
    uni.showToast({
      title: '操作失败，请稍后重试',
      icon: 'none'
    });
  } finally {
    loading.value = false;
  }
};

// 页面挂载时获取省份列表并初始化数据
onMounted(() => {
  fetchProvinces();
  initEditData();
});
</script>

<style scoped>
.address-container {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* 顶部导航栏 */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20rpx 30rpx;
  height: 88rpx;
}

.back-btn {
  width: 60rpx;
  height: 60rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(102, 126, 234, 0.1);
  transition: all 0.3s ease;
}

.back-btn:active {
  background: rgba(102, 126, 234, 0.2);
  transform: scale(0.95);
}

.back-icon {
  font-size: 32rpx;
  color: #667eea;
  font-weight: bold;
}

.header-title {
  font-size: 36rpx;
  font-weight: 700;
  color: #333;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-placeholder {
  width: 60rpx;
}

/* 表单内容 */
.form-content {
  padding: 120rpx 30rpx 200rpx;
}

.form-card {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20rpx;
  padding: 40rpx;
  margin-bottom: 30rpx;
  box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  animation: cardSlideIn 0.6s ease;
}

@keyframes cardSlideIn {
  0% { transform: translateY(30rpx); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

.card-title {
  display: flex;
  align-items: center;
  margin-bottom: 30rpx;
  padding-bottom: 20rpx;
  border-bottom: 2rpx solid #f0f0f0;
}

.title-icon {
  font-size: 32rpx;
  margin-right: 16rpx;
}

.title-text {
  font-size: 32rpx;
  font-weight: 700;
  color: #333;
}

.form-item {
  margin-bottom: 30rpx;
}

.form-label {
  font-size: 28rpx;
  color: #333;
  font-weight: 600;
  margin-bottom: 16rpx;
}

.form-input {
  width: 100%;
  height: 88rpx;
  border: 2rpx solid #e0e0e0;
  border-radius: 12rpx;
  padding: 0 24rpx;
  font-size: 28rpx;
  box-sizing: border-box;
  transition: all 0.3s ease;
  background: #fafafa;
}

.form-input:focus {
  border-color: #667eea;
  background: white;
  box-shadow: 0 0 0 6rpx rgba(102, 126, 234, 0.1);
}

/* 性别选择器 */
.gender-selector {
  display: flex;
  gap: 20rpx;
}

.gender-option {
  flex: 1;
  height: 88rpx;
  border: 2rpx solid #e0e0e0;
  border-radius: 12rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12rpx;
  transition: all 0.3s ease;
  background: #fafafa;
}

.gender-option.active {
  border-color: #667eea;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  transform: translateY(-2rpx);
  box-shadow: 0 6rpx 20rpx rgba(102, 126, 234, 0.3);
}

.gender-icon {
  font-size: 32rpx;
}

.gender-text {
  font-size: 28rpx;
  font-weight: 600;
}

/* 省市区选择器 */
.region-picker {
  display: flex;
  flex-direction: column;
  gap: 20rpx;
}

.picker-item {
  height: 88rpx;
  border: 2rpx solid #e0e0e0;
  border-radius: 12rpx;
  padding: 0 24rpx;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 28rpx;
  color: #333;
  background: #fafafa;
  transition: all 0.3s ease;
}

.picker-item.placeholder {
  color: #999;
}

.picker-item.disabled {
  background: #f5f5f5;
  color: #ccc;
  cursor: not-allowed;
}

.picker-arrow {
  font-size: 24rpx;
  color: #999;
  transition: transform 0.3s ease;
}

.picker-item:active .picker-arrow {
  transform: rotate(180deg);
}

/* 详细地址输入 */
.form-textarea {
  width: 100%;
  min-height: 160rpx;
  border: 2rpx solid #e0e0e0;
  border-radius: 12rpx;
  padding: 24rpx;
  font-size: 28rpx;
  box-sizing: border-box;
  resize: none;
  transition: all 0.3s ease;
  background: #fafafa;
  line-height: 1.5;
}

.form-textarea:focus {
  border-color: #667eea;
  background: white;
  box-shadow: 0 0 0 6rpx rgba(102, 126, 234, 0.1);
}

.char-count {
  text-align: right;
  font-size: 24rpx;
  color: #999;
  margin-top: 12rpx;
}

.char-count.warning {
  color: #ff6b6b;
}

/* 地址预览 */
.address-preview {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  padding: 24rpx;
  border-radius: 12rpx;
  border: 2rpx solid #e9ecef;
}

.preview-text {
  font-size: 28rpx;
  color: #666;
  line-height: 1.5;
}

/* 提交按钮 */
.submit-section {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 30rpx;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.submit-btn {
  width: 100%;
  height: 96rpx;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 48rpx;
  font-size: 32rpx;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 8rpx 32rpx rgba(102, 126, 234, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12rpx;
}

.submit-btn:not(.disabled):active {
  transform: translateY(-2rpx) scale(0.98);
  box-shadow: 0 12rpx 40rpx rgba(102, 126, 234, 0.6);
}

.submit-btn.disabled {
  background: #ccc;
  color: #999;
  box-shadow: none;
  cursor: not-allowed;
}

.btn-text {
  font-size: 32rpx;
  font-weight: 700;
}

.btn-icon {
  font-size: 28rpx;
  font-weight: bold;
}

/* 加载状态 */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(5px);
}

.loading-content {
  background: white;
  padding: 60rpx;
  border-radius: 20rpx;
  text-align: center;
  box-shadow: 0 20rpx 60rpx rgba(0, 0, 0, 0.3);
  animation: loadingSlideIn 0.3s ease;
}

@keyframes loadingSlideIn {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.loading-spinner {
  width: 60rpx;
  height: 60rpx;
  border: 4rpx solid #f3f3f3;
  border-top: 4rpx solid #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 20rpx;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.loading-text {
  font-size: 28rpx;
  color: #333;
  font-weight: 600;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .form-content {
    padding: 100rpx 20rpx 180rpx;
  }
  
  .form-card {
    padding: 30rpx;
  }
  
  .header-title {
    font-size: 32rpx;
  }
}
</style>